/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * prueba2.java
 *
 * Created on May 21, 2011, 10:59:46 PM
 */

package basededatos;

//import Forms.GestionAlmaceness;
//import Forms.GestionCargass;
//import Forms.GestionClientess;
//import Forms.GestionRackss;
//import Forms.GestionServicioss;

//import Forms.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.Dimension;
import java.beans.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Sarazua
 */
public class Main extends javax.swing.JFrame {

    /** Creates new form prueba2 */
    public Main() {
        try {
	    // Set cross-platform Java L&F (also called "Metal")
        UIManager.setLookAndFeel(
            UIManager.getSystemLookAndFeelClassName());
    } 
    catch (Exception e) {
       // handle exception
    }
          initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPaneTODOtAB = new javax.swing.JTabbedPane();
        jPanelREPORTES = new javax.swing.JPanel();
        BotonReporte1 = new javax.swing.JButton();
        BotonReporte2 = new javax.swing.JButton();
        BotonReporte3 = new javax.swing.JButton();
        BotonReporte4 = new javax.swing.JButton();
        BotonReporte5 = new javax.swing.JButton();
        BotonReporte6 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jPanelCONSULTAS = new javax.swing.JPanel();
        cliente_combobox = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        idcarga_field = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        idrack_field = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        servicio_combobox = new javax.swing.JComboBox();
        Consultar_Boton = new javax.swing.JButton();
        mesIngreso = new javax.swing.JComboBox();
        diaIngreso = new javax.swing.JComboBox();
        anioIngreso = new javax.swing.JComboBox();
        anioSalida = new javax.swing.JComboBox();
        mesSalida = new javax.swing.JComboBox();
        diaSalida = new javax.swing.JComboBox();
        idalmacen_field = new javax.swing.JTextField();
        DatosCliente = new javax.swing.JCheckBox();
        EstadoCarga = new javax.swing.JCheckBox();
        EstadoAlmacen = new javax.swing.JCheckBox();
        DatosRack = new javax.swing.JCheckBox();
        includeFI = new javax.swing.JCheckBox();
        includeFE = new javax.swing.JCheckBox();
        jPanelADMIN = new javax.swing.JPanel();
        BotonGestionDeClientes = new javax.swing.JButton();
        BotonGestionDeCargas = new javax.swing.JButton();
        GestionServiciosBoton = new javax.swing.JButton();
        BotonGestionAlmacen = new javax.swing.JButton();
        BotonGestionRack = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SERLIPSA CONTROL");
        setBackground(new java.awt.Color(255, 255, 255));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jTabbedPaneTODOtAB.setBackground(new java.awt.Color(255, 255, 255));
        jTabbedPaneTODOtAB.setFont(new java.awt.Font("Trebuchet MS", 0, 14)); // NOI18N
        jTabbedPaneTODOtAB.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTabbedPaneTODOtABMouseClicked(evt);
            }
        });

        BotonReporte1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/note_edit.png"))); // NOI18N
        BotonReporte1.addContainerListener(new java.awt.event.ContainerAdapter() {
            public void componentAdded(java.awt.event.ContainerEvent evt) {
                BotonReporte1ComponentAdded(evt);
            }
            public void componentRemoved(java.awt.event.ContainerEvent evt) {
                BotonReporte1ComponentRemoved(evt);
            }
        });
        BotonReporte1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonReporte1ActionPerformed(evt);
            }
        });

        BotonReporte2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/cabinet-icon.png"))); // NOI18N
        BotonReporte2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonReporte2ActionPerformed(evt);
            }
        });

        BotonReporte3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/Income-icon.png"))); // NOI18N
        BotonReporte3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonReporte3ActionPerformed(evt);
            }
        });

        BotonReporte4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/money.PNG"))); // NOI18N
        BotonReporte4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonReporte4ActionPerformed(evt);
            }
        });

        BotonReporte5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/calculator.png"))); // NOI18N
        BotonReporte5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonReporte5ActionPerformed(evt);
            }
        });

        BotonReporte6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/Date-and-Time-icon.png"))); // NOI18N
        BotonReporte6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonReporte6ActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Trebuchet MS", 0, 14));
        jLabel3.setText("Reporte de la carga ingresada en un período de tiempo");

        jLabel4.setFont(new java.awt.Font("Trebuchet MS", 0, 14));
        jLabel4.setText("Reporte de estados de los almacenes");

        jLabel5.setFont(new java.awt.Font("Trebuchet MS", 0, 14));
        jLabel5.setText("Reporte de los montos pagados por el cliente para sacar su carga");

        jLabel6.setFont(new java.awt.Font("Trebuchet MS", 0, 14));
        jLabel6.setText("Reporte de la carga egresada en un período de tiempo ");

        jLabel7.setFont(new java.awt.Font("Trebuchet MS", 0, 14));
        jLabel7.setText("Reporte consolidado de los pesos mensuales ingresados y egresados en un año");

        jLabel8.setFont(new java.awt.Font("Trebuchet MS", 0, 14));
        jLabel8.setText("Reporte  de la carga declarada en abandono legal en un período de tiempo");

        javax.swing.GroupLayout jPanelREPORTESLayout = new javax.swing.GroupLayout(jPanelREPORTES);
        jPanelREPORTES.setLayout(jPanelREPORTESLayout);
        jPanelREPORTESLayout.setHorizontalGroup(
            jPanelREPORTESLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelREPORTESLayout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(jPanelREPORTESLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelREPORTESLayout.createSequentialGroup()
                        .addComponent(BotonReporte6, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel8))
                    .addGroup(jPanelREPORTESLayout.createSequentialGroup()
                        .addComponent(BotonReporte5, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel7))
                    .addGroup(jPanelREPORTESLayout.createSequentialGroup()
                        .addComponent(BotonReporte4, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel6))
                    .addGroup(jPanelREPORTESLayout.createSequentialGroup()
                        .addComponent(BotonReporte3, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel5))
                    .addGroup(jPanelREPORTESLayout.createSequentialGroup()
                        .addComponent(BotonReporte2, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel4))
                    .addGroup(jPanelREPORTESLayout.createSequentialGroup()
                        .addComponent(BotonReporte1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel3)))
                .addContainerGap(51, Short.MAX_VALUE))
        );
        jPanelREPORTESLayout.setVerticalGroup(
            jPanelREPORTESLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelREPORTESLayout.createSequentialGroup()
                .addGroup(jPanelREPORTESLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelREPORTESLayout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addComponent(BotonReporte1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(8, 8, 8)
                        .addComponent(BotonReporte2, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(BotonReporte3, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(BotonReporte4, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(BotonReporte5, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(BotonReporte6, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelREPORTESLayout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addComponent(jLabel3)
                        .addGap(28, 28, 28)
                        .addComponent(jLabel4)
                        .addGap(28, 28, 28)
                        .addComponent(jLabel5)
                        .addGap(28, 28, 28)
                        .addComponent(jLabel6)
                        .addGap(29, 29, 29)
                        .addComponent(jLabel7)
                        .addGap(29, 29, 29)
                        .addComponent(jLabel8)))
                .addContainerGap(118, Short.MAX_VALUE))
        );

        jTabbedPaneTODOtAB.addTab("Reportes", jPanelREPORTES);

        jPanelCONSULTAS.setBackground(new java.awt.Color(255, 255, 255));

        cliente_combobox.setModel(new javax.swing.DefaultComboBoxModel());
        cliente_combobox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cliente_comboboxActionPerformed(evt);
            }
        });

        jLabel1.setText("Cliente");

        jLabel2.setText("ID Carga");

        idcarga_field.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                idcarga_fieldActionPerformed(evt);
            }
        });

        jLabel9.setText("Almacen");

        jLabel10.setText("Fecha de Ingreso");

        jLabel11.setText("Fecha de Egreso");

        jLabel12.setText("Rack");

        idrack_field.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                idrack_fieldActionPerformed(evt);
            }
        });

        jLabel13.setText("Servicio");

        servicio_combobox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "", "Aforo", "Almacenaje"}));
        servicio_combobox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                servicio_comboboxActionPerformed(evt);
            }
        });

        Consultar_Boton.setText("Buscar");
        Consultar_Boton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Consultar_BotonActionPerformed(evt);
            }
        });

        mesIngreso.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ENE", "FEB", "MAR", "ABR", "MAY", "JUN", "JUL", "AGO", "SEP", "OCT", "NOV", "DIC" }));

        diaIngreso.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31" }));
        diaIngreso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                diaIngresoActionPerformed(evt);
            }
        });

        anioIngreso.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015",  }));

        anioSalida.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015",  }));

        mesSalida.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ENE", "FEB", "MAR", "ABR", "MAY", "JUN", "JUL", "AGO", "SEP", "OCT", "NOV", "DIC" }));

        diaSalida.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31" }));
        diaSalida.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                diaSalidaActionPerformed(evt);
            }
        });

        idalmacen_field.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                idalmacen_fieldActionPerformed(evt);
            }
        });

        DatosCliente.setBackground(new java.awt.Color(255, 255, 255));
        DatosCliente.setText("Mostrar datos completos de cliente");

        EstadoCarga.setBackground(new java.awt.Color(255, 255, 255));
        EstadoCarga.setText("Mostrar estado de la carga");
        EstadoCarga.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EstadoCargaActionPerformed(evt);
            }
        });

        EstadoAlmacen.setBackground(new java.awt.Color(255, 255, 255));
        EstadoAlmacen.setText("Mostrar estado de almacen");

        DatosRack.setBackground(new java.awt.Color(255, 255, 255));
        DatosRack.setText("Mostrar datos del Rack");

        includeFI.setText("Incluir fecha de ingreso");

        includeFE.setText("Incluir fecha de egreso");

        javax.swing.GroupLayout jPanelCONSULTASLayout = new javax.swing.GroupLayout(jPanelCONSULTAS);
        jPanelCONSULTAS.setLayout(jPanelCONSULTASLayout);
        jPanelCONSULTASLayout.setHorizontalGroup(
            jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelCONSULTASLayout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(EstadoCarga)
                    .addGroup(jPanelCONSULTASLayout.createSequentialGroup()
                        .addGroup(jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel9)
                            .addComponent(jLabel12))
                        .addGap(18, 18, 18)
                        .addGroup(jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(idcarga_field, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(idalmacen_field, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cliente_combobox, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(idrack_field, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(70, 70, 70)
                        .addGroup(jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelCONSULTASLayout.createSequentialGroup()
                                .addGroup(jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(EstadoAlmacen)
                                    .addComponent(DatosRack)
                                    .addGroup(jPanelCONSULTASLayout.createSequentialGroup()
                                        .addGroup(jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel10)
                                            .addComponent(jLabel11)
                                            .addComponent(jLabel13))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGroup(jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(servicio_combobox, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGroup(jPanelCONSULTASLayout.createSequentialGroup()
                                                .addGroup(jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                    .addGroup(jPanelCONSULTASLayout.createSequentialGroup()
                                                        .addComponent(anioIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(mesIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                    .addGroup(jPanelCONSULTASLayout.createSequentialGroup()
                                                        .addComponent(anioSalida, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(mesSalida, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                .addGap(6, 6, 6)
                                                .addGroup(jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(diaSalida, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(diaIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                            .addComponent(Consultar_Boton, javax.swing.GroupLayout.Alignment.TRAILING))))
                                .addGap(71, 71, 71))
                            .addGroup(jPanelCONSULTASLayout.createSequentialGroup()
                                .addComponent(includeFI)
                                .addGap(18, 18, 18)
                                .addComponent(includeFE)))
                        .addGap(85, 85, 85))
                    .addComponent(DatosCliente))
                .addContainerGap())
        );
        jPanelCONSULTASLayout.setVerticalGroup(
            jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelCONSULTASLayout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelCONSULTASLayout.createSequentialGroup()
                        .addGroup(jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jLabel10)
                            .addComponent(cliente_combobox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11)
                            .addComponent(jLabel2)
                            .addComponent(idcarga_field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelCONSULTASLayout.createSequentialGroup()
                                .addGroup(jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(idalmacen_field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel12)
                                    .addComponent(idrack_field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanelCONSULTASLayout.createSequentialGroup()
                                .addGap(3, 3, 3)
                                .addComponent(jLabel13)
                                .addGap(18, 18, 18)
                                .addGroup(jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(includeFI)
                                    .addComponent(includeFE)))))
                    .addGroup(jPanelCONSULTASLayout.createSequentialGroup()
                        .addGroup(jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(diaIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(anioIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(mesIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(anioSalida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(mesSalida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(diaSalida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(servicio_combobox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(DatosCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(EstadoAlmacen))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelCONSULTASLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(EstadoCarga)
                    .addComponent(DatosRack)
                    .addComponent(Consultar_Boton))
                .addContainerGap(213, Short.MAX_VALUE))
        );

        jTabbedPaneTODOtAB.addTab("Consultas", jPanelCONSULTAS);

        jPanelADMIN.setBackground(new java.awt.Color(255, 255, 255));

        BotonGestionDeClientes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/users.png"))); // NOI18N
        BotonGestionDeClientes.setToolTipText("Gestion de Clientes\n");
        BotonGestionDeClientes.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BotonGestionDeClientes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                BotonGestionDeClientesMouseClicked(evt);
            }
        });
        BotonGestionDeClientes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonGestionDeClientesActionPerformed(evt);
            }
        });

        BotonGestionDeCargas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/ForkliftTruck_Loaded_Black.png"))); // NOI18N
        BotonGestionDeCargas.setToolTipText("Gestion de Carga");
        BotonGestionDeCargas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonGestionDeCargasActionPerformed(evt);
            }
        });

        GestionServiciosBoton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/history.png"))); // NOI18N
        GestionServiciosBoton.setToolTipText("Gestion de Servicios");
        GestionServiciosBoton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GestionServiciosBotonActionPerformed(evt);
            }
        });

        BotonGestionAlmacen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/industry.png"))); // NOI18N
        BotonGestionAlmacen.setToolTipText("Gestion de Almacenes");
        BotonGestionAlmacen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonGestionAlmacenActionPerformed(evt);
            }
        });

        BotonGestionRack.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/Container_Red.png"))); // NOI18N
        BotonGestionRack.setToolTipText("Gestion de Racks");
        BotonGestionRack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonGestionRackActionPerformed(evt);
            }
        });

        jLabel15.setFont(new java.awt.Font("Trebuchet MS", 0, 18));
        jLabel15.setText("Gestión de Clientes");

        jLabel16.setFont(new java.awt.Font("Trebuchet MS", 0, 18));
        jLabel16.setText("Gestión de Cargas");

        jLabel17.setFont(new java.awt.Font("Trebuchet MS", 0, 18));
        jLabel17.setText("Gestión de Servicios");

        jLabel18.setFont(new java.awt.Font("Trebuchet MS", 0, 18));
        jLabel18.setText("Gestión de Almacenes");

        jLabel19.setFont(new java.awt.Font("Trebuchet MS", 0, 18));
        jLabel19.setText("Gestión de Racks");

        javax.swing.GroupLayout jPanelADMINLayout = new javax.swing.GroupLayout(jPanelADMIN);
        jPanelADMIN.setLayout(jPanelADMINLayout);
        jPanelADMINLayout.setHorizontalGroup(
            jPanelADMINLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelADMINLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelADMINLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(BotonGestionRack, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(BotonGestionAlmacen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(GestionServiciosBoton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(BotonGestionDeCargas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(BotonGestionDeClientes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, Short.MAX_VALUE)
                .addGroup(jPanelADMINLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel18)
                    .addComponent(jLabel17)
                    .addComponent(jLabel16)
                    .addComponent(jLabel15)
                    .addComponent(jLabel19))
                .addGap(336, 336, 336))
        );
        jPanelADMINLayout.setVerticalGroup(
            jPanelADMINLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelADMINLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(BotonGestionDeClientes, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(BotonGestionDeCargas, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(GestionServiciosBoton, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(BotonGestionAlmacen, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(BotonGestionRack, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(16, Short.MAX_VALUE))
            .addGroup(jPanelADMINLayout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(jLabel15)
                .addGap(57, 57, 57)
                .addComponent(jLabel16)
                .addGap(58, 58, 58)
                .addComponent(jLabel17)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
                .addComponent(jLabel18)
                .addGap(60, 60, 60)
                .addComponent(jLabel19)
                .addGap(47, 47, 47))
        );

        jTabbedPaneTODOtAB.addTab("Admin", jPanelADMIN);

        jLabel14.setFont(new java.awt.Font("Trebuchet MS", 1, 24));
        jLabel14.setText("SERLIPSA");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jTabbedPaneTODOtAB, javax.swing.GroupLayout.PREFERRED_SIZE, 626, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(269, 269, 269)
                        .addComponent(jLabel14)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(11, 11, 11)
                .addComponent(jTabbedPaneTODOtAB, javax.swing.GroupLayout.PREFERRED_SIZE, 447, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
   
    private void BotonReporte1ComponentAdded(java.awt.event.ContainerEvent evt) {//GEN-FIRST:event_BotonReporte1ComponentAdded
        // TODO add your handling code here:
}//GEN-LAST:event_BotonReporte1ComponentAdded

    private void BotonReporte1ComponentRemoved(java.awt.event.ContainerEvent evt) {//GEN-FIRST:event_BotonReporte1ComponentRemoved
        // TODO add your handling code here:
}//GEN-LAST:event_BotonReporte1ComponentRemoved

    private void BotonReporte1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonReporte1ActionPerformed
String periodoInicio = JOptionPane.showInputDialog("Ingrese la fecha de inicio del periodo aa-mm-dd");
    String periodoFinal = JOptionPane.showInputDialog("Ingrese la fecha de final del periodo aa-mm-dd");
    Date fechaInicio = null, fechaFinal = null;
    SimpleDateFormat formato = new SimpleDateFormat("yyyy-MM-dd");
    try {
        fechaInicio = formato.parse(periodoInicio);
        fechaFinal = formato.parse(periodoFinal);
    } catch (ParseException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(null, "Error al ingresar la fecha");
    }
    if (fechaInicio.equals(fechaFinal) || (fechaInicio.before(fechaFinal))) {
        try {
            java.sql.Statement inst = conexion.createStatement();
            String querry = "Select * from reporte1(cast('"+periodoInicio+"' as date), cast('"+periodoFinal+"' as date)) as (IdCarga integer, IdCliente integer, NombreCliente varchar(200), FechaIngreso timestamp, FechaSalida timestamp, Refrigerada boolean, PesoCarga numeric, IdAlmacen integer, Fila integer, Columna integer, IdRack integer)";
            ResultSet rs = inst.executeQuery(querry);
            //Obteniendo datos de la base de datos e ingresandolos a una Jtable
            DefaultTableModel modelo = new DefaultTableModel();
            JTable tabla = new JTable(modelo);
            ResultSetMetaData metaDatos = rs.getMetaData();
            int numColumnas = metaDatos.getColumnCount();
            Object[] etiquetas = new Object[numColumnas];
            for (int i = 0; i < numColumnas; i++) {
                etiquetas[i] = metaDatos.getColumnLabel(i + 1);
               // System.out.println(etiquetas[i]);
            }
            modelo.setColumnIdentifiers(etiquetas);
            while (rs.next()) {
                Object[] fila = new Object[numColumnas];
                for (int j = 0; j < numColumnas; j++) {
                    fila[j] = rs.getObject(j + 1);
                }
                modelo.addRow(fila);
            }

            inst.execute("END");
            inst.close();
            // Agregar la tabla a un Panel
            JScrollPane scroll = new JScrollPane(tabla);
            //tabla.setAutoResizeMode(tabla.AUTO_RESIZE_ALL_COLUMNS);
            tabla.setVisible(true);
            JPanel panel = new JPanel();
            panel.add(scroll);
            JFrame frame = new JFrame();
            frame.add(panel);
            frame.pack();
            frame.setVisible(true);

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Error en el ingreso");
        }
    } else {
        JOptionPane.showMessageDialog(null, "El periodo no es valido");
    }
}//GEN-LAST:event_BotonReporte1ActionPerformed

    private void BotonReporte2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonReporte2ActionPerformed
        try {
            java.sql.Statement inst = conexion.createStatement();
            String querry = "Select * from reporte2() as(idalmacen integer, estado boolean, idrack int, fila int, columna int, peso numeric)";
            ResultSet rs = inst.executeQuery(querry);
            //Obteniendo datos de la base de datos e ingresandolos a una Jtable
            DefaultTableModel modelo = new DefaultTableModel();
            JTable tabla = new JTable(modelo);
            ResultSetMetaData metaDatos = rs.getMetaData();
            int numColumnas = metaDatos.getColumnCount();
            Object[] etiquetas = new Object[numColumnas];
            for (int i = 0; i < numColumnas; i++) {
                etiquetas[i] = metaDatos.getColumnLabel(i + 1);
                //System.out.println(etiquetas[i]);
            }
            modelo.setColumnIdentifiers(etiquetas);
            while (rs.next()) {
                Object[] fila = new Object[numColumnas];
                for (int j = 0; j < numColumnas; j++) {
                    fila[j] = rs.getObject(j + 1);
                }
                modelo.addRow(fila);
            }

            inst.execute("END");
            inst.close();
            // Agregar la tabla a un Panel
            JScrollPane scroll = new JScrollPane(tabla);
            //tabla.setAutoResizeMode(tabla.AUTO_RESIZE_ALL_COLUMNS);
            tabla.setVisible(true);
            JPanel panel = new JPanel();
            panel.add(scroll);
            JFrame frame = new JFrame();
            frame.add(panel);
            frame.pack();
            frame.setVisible(true);
            
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Error en el ingreso");
        }


}//GEN-LAST:event_BotonReporte2ActionPerformed

    private void BotonReporte5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonReporte5ActionPerformed
    String idClient = JOptionPane.showInputDialog("Ingrese el año que desea (AAAA)");
    try{
    int idCliente = Integer.parseInt (idClient);
    try {
            java.sql.Statement inst = conexion.createStatement();
            String querry = "Select * FROM reporte5(2011) as (mes text, cargatotalingresada numeric, ctotalegresada numeric, movimiento varchar, montoc numeric)";
            ResultSet rs = inst.executeQuery(querry);
            //Obteniendo datos de la base de datos e ingresandolos a una Jtable
            DefaultTableModel modelo = new DefaultTableModel();
            JTable tabla = new JTable(modelo);
            ResultSetMetaData metaDatos = rs.getMetaData();
            int numColumnas = metaDatos.getColumnCount();
            Object[] etiquetas = new Object[numColumnas];
            for (int i = 0; i < numColumnas; i++) {
                etiquetas[i] = metaDatos.getColumnLabel(i + 1);
                //System.out.println(etiquetas[i]);
            }
            modelo.setColumnIdentifiers(etiquetas);
            while (rs.next()) {
                Object[] fila = new Object[numColumnas];
                for (int j = 0; j < numColumnas; j++) {
                    fila[j] = rs.getObject(j + 1);
                }
                modelo.addRow(fila);
            }

            inst.execute("END");
            inst.close();
            // Agregar la tabla a un Panel
            JScrollPane scroll = new JScrollPane(tabla);
            //tabla.setAutoResizeMode(tabla.AUTO_RESIZE_ALL_COLUMNS);
            tabla.setVisible(true);
            JPanel panel = new JPanel();
            panel.add(scroll);
            JFrame frame = new JFrame();
            frame.add(panel);
            frame.pack();
            frame.setVisible(true);

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Error en el ingreso");
        }
    }catch(Exception e){
        JOptionPane.showMessageDialog(null, "Error al ingresar el año");
    }

}//GEN-LAST:event_BotonReporte5ActionPerformed

    private void BotonReporte6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonReporte6ActionPerformed
try {
            java.sql.Statement inst = conexion.createStatement();
            String querry = "select * from reporte6() as (IDcarga integer, IdAlmacen integer, fila integer, columna integer, IDrack integer, FechaSalida timestamp)";
            ResultSet rs = inst.executeQuery(querry);
            //Obteniendo datos de la base de datos e ingresandolos a una Jtable
            DefaultTableModel modelo = new DefaultTableModel();
            JTable tabla = new JTable(modelo);
            ResultSetMetaData metaDatos = rs.getMetaData();
            int numColumnas = metaDatos.getColumnCount();
            Object[] etiquetas = new Object[numColumnas];
            for (int i = 0; i < numColumnas; i++) {
                etiquetas[i] = metaDatos.getColumnLabel(i + 1);
                //System.out.println(etiquetas[i]);
            }
            modelo.setColumnIdentifiers(etiquetas);
            while (rs.next()) {
                Object[] fila = new Object[numColumnas];
                for (int j = 0; j < numColumnas; j++) {
                    fila[j] = rs.getObject(j + 1);
                }
                modelo.addRow(fila);
            }

            inst.execute("END");
            inst.close();
            // Agregar la tabla a un Panel
            JScrollPane scroll = new JScrollPane(tabla);
            //tabla.setAutoResizeMode(tabla.AUTO_RESIZE_ALL_COLUMNS);
            tabla.setVisible(true);
            JPanel panel = new JPanel();
            panel.add(scroll);
            JFrame frame = new JFrame();
            frame.add(panel);
            frame.pack();
            frame.setVisible(true);

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(jPanelCONSULTAS, "OOPS! ha ocurrido un error", "ERROR", JOptionPane.ERROR_MESSAGE);
            //Logger.getLogger(prueba2.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_BotonReporte6ActionPerformed

    private void BotonGestionDeClientesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_BotonGestionDeClientesMouseClicked
        // TODO add your handling code here:
}//GEN-LAST:event_BotonGestionDeClientesMouseClicked

    private void ShowTablePanel(String consulta){
        try {
            java.sql.Statement inst = conexion.createStatement();
            String querry = consulta;
            ResultSet rs = inst.executeQuery(querry);
            //Obteniendo datos de la base de datos e ingresandolos a una Jtable
            DefaultTableModel modelo = new DefaultTableModel();
            JTable tabla = new JTable(modelo);
            ResultSetMetaData metaDatos = rs.getMetaData();
            int numColumnas = metaDatos.getColumnCount();
            Object[] etiquetas = new Object[numColumnas];
            for (int i = 0; i < numColumnas; i++) {
                etiquetas[i] = metaDatos.getColumnLabel(i + 1);
                System.out.println(etiquetas[i]);
            }
            modelo.setColumnIdentifiers(etiquetas);
            while (rs.next()) {
                Object[] fila = new Object[numColumnas];
                for (int j = 0; j < numColumnas; j++) {
                    fila[j] = rs.getObject(j + 1);
                }
                modelo.addRow(fila);
            }

            inst.execute("END");
            inst.close();
            // Agregar la tabla a un Panel
            JScrollPane scroll = new JScrollPane(tabla);
            //tabla.setAutoResizeMode(tabla.AUTO_RESIZE_ALL_COLUMNS);
            tabla.setVisible(true);
            JPanel panel = new JPanel();
            panel.add(scroll);
            JFrame frame = new JFrame();
            frame.add(panel);
            frame.pack();
                frame.setVisible(true);
//              FramePrueba.add(panel);
//              FramePrueba.pack();
//              FramePrueba.setVisible(true);
            
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(jPanelCONSULTAS, "OOPS! Ha ocurrido un error con la consulta", "ERROR", JOptionPane.ERROR_MESSAGE);

            //Logger.getLogger(prueba2.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    private void BotonGestionDeClientesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonGestionDeClientesActionPerformed
                new GestionClientes().setVisible(true);
}//GEN-LAST:event_BotonGestionDeClientesActionPerformed

private void cliente_comboboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cliente_comboboxActionPerformed
 
}//GEN-LAST:event_cliente_comboboxActionPerformed

private  static Object makeObj(final String item)  {
     return new Object() {@Override
 public String toString() { return item; } };
   }

private void idcarga_fieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_idcarga_fieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_idcarga_fieldActionPerformed

private void idrack_fieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_idrack_fieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_idrack_fieldActionPerformed

private void diaIngresoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_diaIngresoActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_diaIngresoActionPerformed

private void servicio_comboboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_servicio_comboboxActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_servicio_comboboxActionPerformed

private void diaSalidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_diaSalidaActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_diaSalidaActionPerformed

private void BotonGestionDeCargasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonGestionDeCargasActionPerformed
                new GestionCargas().setVisible(true);
}//GEN-LAST:event_BotonGestionDeCargasActionPerformed

private void GestionServiciosBotonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GestionServiciosBotonActionPerformed
                //JFrame frame = new JFrame();
//                frame.setContentPane(new GestionServicios());
//                //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//                frame.pack();
//                frame.setVisible(true);
                   new GestionServicios().setVisible(true);
}//GEN-LAST:event_GestionServiciosBotonActionPerformed


public static void SetClientComboBox(){
        try {
            java.sql.Statement inst = conexion.createStatement();        
            String querry = "Select nombre from Cliente order by nombre";
            ResultSet rs = inst.executeQuery(querry);
            int r=0;
            while(rs.next()){
                r++;
            }
            ResultSet rs2 = inst.executeQuery(querry);
            String lista_clientes[] = new String[r];
            for(int i=0;rs2.next();i++){
                lista_clientes[i]=rs2.getString(1);
            }
            cliente_combobox.addItem(makeObj(""));
            for(int k=0; k<lista_clientes.length; k++){
                cliente_combobox.addItem(makeObj(lista_clientes[k]));
            }
        } catch (SQLException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

private void idalmacen_fieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_idalmacen_fieldActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event_idalmacen_fieldActionPerformed

private void Consultar_BotonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Consultar_BotonActionPerformed
    String nombre_cliente = cliente_combobox.getSelectedItem().toString();
    String idcarga = idcarga_field.getText();
    String idalmacen = idalmacen_field.getText();
    String idrack = idrack_field.getText();
    String anioI = anioIngreso.getSelectedItem().toString();
    String mesI = mesIngreso.getSelectedItem().toString();
    String diaI = diaIngreso.getSelectedItem().toString();
    String anioE = anioSalida.getSelectedItem().toString();
    String mesE = mesSalida.getSelectedItem().toString();
    String diaE = diaSalida.getSelectedItem().toString();
    String servicio = servicio_combobox.getSelectedItem().toString();
    
    String SELECT = "SELECT DISTINCT Cliente.idcliente, nombre,";
        if(DatosCliente.isSelected()){
            SELECT+="apellido, direccion, telefono,";
        }
    SELECT+="Carga.idcarga";
    if(includeFI.isSelected())
        SELECT+=",fechaIngreso";
    if(includeFE.isSelected())
        SELECT+=", fechaSalida";
    if(EstadoCarga.isSelected())
        SELECT+=",peso,(CASE WHEN estado=true THEN 'Abandonada' ELSE 'Activa' END), "
                + "(CASE WHEN refrigerada=true THEN 'Refrigerada' ELSE 'Normal' END) as TipoAlmacenaje";
    //SELECT+=",Almacen.idalmacen";
    if(EstadoAlmacen.isSelected())
        SELECT+=",(CASE WHEN Almacen.estado=true THEN 'Lleno' ELSE 'Libre' END), espaciolibre";
    //SELECT+=",Rack.idRack";
    if(DatosRack.isSelected())
        SELECT+=",fila, columna";
    
    String FROM = " FROM Cliente, Carga";
    
    if(idalmacen.length()>0 || EstadoAlmacen.isSelected())
        FROM+=",Almacen";
    if(idrack.length()>0 || DatosRack.isSelected())
        FROM+=",Rack";
    if(servicio.length()>0)
        FROM+=",Servicio";
    if(FROM.endsWith(","))
        FROM = FROM.substring(0, FROM.length()-1);
    
    String WHERE = " WHERE ";
    if(nombre_cliente.length()>0)
        WHERE+="Cliente.nombre='" + nombre_cliente+"' and "; 
    if(idcarga.length()>0)
        WHERE+="Carga.idCarga="+idcarga+" and CLiente.idcliente=Carga.idcliente and ";
    if(idalmacen.length()>0)
        WHERE+="Almacen.idalmacen="+idalmacen+" and ";
    if(idrack.length()>0){
        WHERE+="Rack.idrack="+idrack+" and Rack.idrack=Carga.idrack and ";
        if(idalmacen.length()>0)
        WHERE+="Almacen.idalmacen=Rack.idalmacen and ";
    }
    if(includeFI.isSelected()){
        String fecha = anioI+"-"+getMonthNumber(mesI)+"-"+diaI;
        WHERE+="date(fechaIngreso)=cast('"+fecha+"' as date) and ";
    }
    if(includeFE.isSelected()){
        String fecha = anioE+"-"+getMonthNumber(mesE)+"-"+diaE;
        WHERE+="date(fechaSalida)=cast('"+fecha+"' as date) and ";
    }
    if(servicio.length()>0)
        WHERE+="servicio.tipo="+servicio+" and servicio.idcarga = carga.idcarga";
    if(WHERE.endsWith("and ")){
        WHERE=WHERE.substring(0, WHERE.length()-5);
    }
    String consulta = SELECT+FROM+WHERE;
    System.out.println(consulta);
    ShowTablePanel(consulta);
}//GEN-LAST:event_Consultar_BotonActionPerformed

private String getMonthNumber(String mes){
    String retorno="";
    if(mes.equals("ENE"))
        retorno="01";
    if(mes.equals("FEB"))
        retorno="02";
    if(mes.equals("MAR"))
        retorno="03";
    if(mes.equals("ABR"))
        retorno="04";
    if(mes.equals("MAY"))
        retorno="05";
    if(mes.equals("JUN"))
        retorno="06";
    if(mes.equals("JUL"))
        retorno="07";
    if(mes.equals("AGO"))
        retorno="08";
    if(mes.equals("SEP"))
        retorno="09";
    if(mes.equals("OCT"))
        retorno="10";
    if(mes.equals("NOV"))
        retorno="11";
    if(mes.equals("DIC"))
        retorno="12";
    return retorno;
}

private void EstadoCargaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EstadoCargaActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event_EstadoCargaActionPerformed
    



private static Connection conexion;


private void BotonReporte3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonReporte3ActionPerformed

        String idClient = JOptionPane.showInputDialog("Ingrese el Id del cliente por el cual desea buscar");
    try {
            java.sql.Statement inst = conexion.createStatement();
            String querry = "select * from reporte3("+idClient+ ") as (IDcarga integer, FechaIngreso timestamp, FechaSalida timestamp, IDservicio Integer,Tipo varchar(10),MontoServicio numeric, Peso numeric, MontoC numeric)";
            ResultSet rs = inst.executeQuery(querry);
            //Obteniendo datos de la base de datos e ingresandolos a una Jtable
            DefaultTableModel modelo = new DefaultTableModel();
            JTable tabla = new JTable(modelo);
            ResultSetMetaData metaDatos = rs.getMetaData();
            int numColumnas = metaDatos.getColumnCount();
            Object[] etiquetas = new Object[numColumnas];
            for (int i = 0; i < numColumnas; i++) {
                etiquetas[i] = metaDatos.getColumnLabel(i + 1);
                //System.out.println(etiquetas[i]);
            }
            modelo.setColumnIdentifiers(etiquetas);
            while (rs.next()) {
                Object[] fila = new Object[numColumnas];
                for (int j = 0; j < numColumnas; j++) {
                    fila[j] = rs.getObject(j + 1);
                }
                modelo.addRow(fila);
            }

            inst.execute("END");
            inst.close();
            // Agregar la tabla a un Panel
            JScrollPane scroll = new JScrollPane(tabla);
            //tabla.setAutoResizeMode(tabla.AUTO_RESIZE_ALL_COLUMNS);
            tabla.setVisible(true);
            JPanel panel = new JPanel();
            panel.add(scroll);
            JFrame frame = new JFrame();
            frame.add(panel);
            frame.pack();
            frame.setVisible(true);

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Error en el ingreso");
        }

}//GEN-LAST:event_BotonReporte3ActionPerformed

private void BotonReporte4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonReporte4ActionPerformed
    String periodoInicio = JOptionPane.showInputDialog("Ingrese la fecha de inicio del periodo aa-mm-dd");
    String periodoFinal = JOptionPane.showInputDialog("Ingrese la fecha de final del periodo aa-mm-dd");
    Date fechaInicio = null, fechaFinal = null;
    SimpleDateFormat formato = new SimpleDateFormat("yyyy-MM-dd");
    try {
        fechaInicio = formato.parse(periodoInicio);
        fechaFinal = formato.parse(periodoFinal);
    } catch (ParseException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(null, "Error al ingresar la fecha");
    }
    if (fechaInicio.equals(fechaFinal) || (fechaInicio.before(fechaFinal))) {
        try {
            java.sql.Statement inst = conexion.createStatement();
            String querry = "Select * from reporte4(cast('"+periodoInicio+"' as date), cast('"+periodoFinal+"' as date)) as (IdCarga integer, FechaIngreso timestamp, FechaSalida timestamp, PesoCarga numeric, IdAlmacen integer, Fila integer, Columna integer, IdRack integer)";
            ResultSet rs = inst.executeQuery(querry);
            //Obteniendo datos de la base de datos e ingresandolos a una Jtable
            DefaultTableModel modelo = new DefaultTableModel();
            JTable tabla = new JTable(modelo);
            ResultSetMetaData metaDatos = rs.getMetaData();
            int numColumnas = metaDatos.getColumnCount();
            Object[] etiquetas = new Object[numColumnas];
            for (int i = 0; i < numColumnas; i++) {
                etiquetas[i] = metaDatos.getColumnLabel(i + 1);
                //System.out.println(etiquetas[i]);
            }
            modelo.setColumnIdentifiers(etiquetas);
            while (rs.next()) {
                Object[] fila = new Object[numColumnas];
                for (int j = 0; j < numColumnas; j++) {
                    fila[j] = rs.getObject(j + 1);
                }
                modelo.addRow(fila);
            }

            inst.execute("END");
            inst.close();
            // Agregar la tabla a un Panel
            JScrollPane scroll = new JScrollPane(tabla);
            //tabla.setAutoResizeMode(tabla.AUTO_RESIZE_ALL_COLUMNS);
            tabla.setVisible(true);
            JPanel panel = new JPanel();
            panel.add(scroll);
            JFrame frame = new JFrame();
            frame.add(panel);
            frame.pack();
            frame.setVisible(true);

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Error con el ingreso");
        }
    } else {
        JOptionPane.showMessageDialog(null, "El periodo no es valido");
    }
}//GEN-LAST:event_BotonReporte4ActionPerformed

private void BotonGestionAlmacenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonGestionAlmacenActionPerformed
                new GestionAlmacenes().setVisible(true);
}//GEN-LAST:event_BotonGestionAlmacenActionPerformed

private void BotonGestionRackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonGestionRackActionPerformed
                new GestionRacks().setVisible(true);
}//GEN-LAST:event_BotonGestionRackActionPerformed

private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
    System.out.println("SE cerro la ventana");
}//GEN-LAST:event_formWindowClosed

private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
    CloseConection();
    System.out.println("Se ha cerrado la conexion con la BD");
}//GEN-LAST:event_formWindowClosing

private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        String[] users = {"david:admin", "asucena:admin", "admin:admin"};
        try{
            String user = JOptionPane.showInputDialog("Ingrese su nombre de usuario");
            JPasswordField pwd = new JPasswordField(10);  
            //int action = JOptionPane.showConfirmDialog(null, pwd,"Enter Password",JOptionPane.OK_CANCEL_OPTION);
            JOptionPane.showConfirmDialog(null,pwd, "Ingrese su contraseña",JOptionPane.OK_CANCEL_OPTION);
            String pass= new String(pwd.getPassword());
            //System.out.println(pass);
            //String pass= JOptionPane.showInputDialog("Ingrese su contraseña");
            String usrdata = user.trim()+":"+pass.trim();
            System.out.println(usrdata);
            boolean flag=false;
            for(int i=0;i<users.length;i++){
                if(usrdata.equals(users[i])){
                    //System.out.println("ES ADMIN");
                    flag=true;
                }
            }
            if(flag==false)
                JOptionPane.showMessageDialog(null, "No tiene permisos de administrador");
            BotonGestionDeClientes.setEnabled(flag);
            BotonGestionDeCargas.setEnabled(flag);
            GestionServiciosBoton.setEnabled(flag);
            BotonGestionAlmacen.setEnabled(flag);
            BotonGestionRack.setEnabled(flag);
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Hubo un error con su login");
            jPanelADMIN.setVisible(false);
        }
}//GEN-LAST:event_formWindowOpened

private void jTabbedPaneTODOtABMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTabbedPaneTODOtABMouseClicked
        
}//GEN-LAST:event_jTabbedPaneTODOtABMouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        
        
      
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                String driver, user, pass, direccion;
                try {
                    ParseXML.ParseSysXML();
                    driver = "org.postgresql.Driver";
                    //user = "postgres";
                    //pass = "aurora";
                    user=ParseXML.user;
                    pass=ParseXML.passwd;
                    direccion = "jdbc:postgresql://localhost:5432/serbd/";

                    Class.forName(driver);
                    conexion = DriverManager.getConnection(direccion, user, pass);
                    System.out.println("Se ha conectado exitosamente a la BD");
                    new Main().setVisible(true);
                    
                    SetClientComboBox();
                    //conexion.close();
                } catch (Exception e) {
                    System.out.println("No se pudo realizar la Conexion");
                    e.printStackTrace();
                }
            }
            
        });
    }

    public void CloseConection(){
        try {
            conexion.close();
        } catch (SQLException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BotonGestionAlmacen;
    private javax.swing.JButton BotonGestionDeCargas;
    private javax.swing.JButton BotonGestionDeClientes;
    private javax.swing.JButton BotonGestionRack;
    private javax.swing.JButton BotonReporte1;
    private javax.swing.JButton BotonReporte2;
    private javax.swing.JButton BotonReporte3;
    private javax.swing.JButton BotonReporte4;
    private javax.swing.JButton BotonReporte5;
    private javax.swing.JButton BotonReporte6;
    private javax.swing.JButton Consultar_Boton;
    private javax.swing.JCheckBox DatosCliente;
    private javax.swing.JCheckBox DatosRack;
    private javax.swing.JCheckBox EstadoAlmacen;
    private javax.swing.JCheckBox EstadoCarga;
    private javax.swing.JButton GestionServiciosBoton;
    private javax.swing.JComboBox anioIngreso;
    private javax.swing.JComboBox anioSalida;
    private static javax.swing.JComboBox cliente_combobox;
    private javax.swing.JComboBox diaIngreso;
    private javax.swing.JComboBox diaSalida;
    private javax.swing.JTextField idalmacen_field;
    private javax.swing.JTextField idcarga_field;
    private javax.swing.JTextField idrack_field;
    private javax.swing.JCheckBox includeFE;
    private javax.swing.JCheckBox includeFI;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanelADMIN;
    private javax.swing.JPanel jPanelCONSULTAS;
    private javax.swing.JPanel jPanelREPORTES;
    private javax.swing.JTabbedPane jTabbedPaneTODOtAB;
    private javax.swing.JComboBox mesIngreso;
    private javax.swing.JComboBox mesSalida;
    private javax.swing.JComboBox servicio_combobox;
    // End of variables declaration//GEN-END:variables

    private void conexionReporte1(Date fechaInicio, Date fechaFinal) throws ClassNotFoundException, SQLException {
        String FInicio=null,FFinal=null;
        SimpleDateFormat formato = new SimpleDateFormat("yyyy-MM-dd");
        try{
            FInicio = formato.format(fechaInicio);
            System.out.println("fecha inicio"+FInicio);
            FFinal = formato.format(fechaFinal);
        } catch(Exception e){
            JOptionPane.showMessageDialog(null,"Error al ingresar la fecha");
        }

       java.sql.Statement inst = conexion.createStatement();        
        String querry = "Select * from reporte1(cast('"+FInicio+"' as date), cast('"+FFinal+"' as date)) as (IdCarga integer, IdCliente integer, NombreCliente varchar(200), FechaIngreso timestamp, FechaSalida timestamp, Refrigerada boolean, PesoCarga numeric, IdAlmacen integer, Fila integer, Columna integer, IdRack integer)";
        ResultSet rs = inst.executeQuery(querry);        

        DefaultTableModel modelo = new DefaultTableModel();
        JTable tabla = new JTable(modelo);
        ResultSetMetaData metaDatos = rs.getMetaData();
        int numColumnas = metaDatos.getColumnCount();
        Object[] etiquetas = new Object[numColumnas];
        for (int i = 0; i < numColumnas; i++) {
             etiquetas[i] = metaDatos.getColumnLabel(i + 1);
             System.out.println(etiquetas[i]);
        }
        modelo.setColumnIdentifiers(etiquetas);
        while (rs.next()){
             Object [] fila = new Object[numColumnas];
             for (int j=0;j<numColumnas;j++)
                   fila[j] = rs.getObject(j+1);                   
                    modelo.addRow(fila);                               
        }
         //setAutoResizeMode(JTable.	AUTO_RESIZE_ALL_COLUMNS);
        inst.execute("END");
        inst.close();        
        JScrollPane scroll = new JScrollPane(tabla);
        tabla.setAutoResizeMode(tabla.AUTO_RESIZE_ALL_COLUMNS);
        //tabla.setPreferredScrollableViewportSize(new Dimension(500,70));
        //tabla.AUTO_RESIZE_ALL_COLUMNS;
        tabla.setVisible(true);
        JPanel panel = new JPanel();
        panel.add(scroll);        
        JFrame frame = new JFrame();
        //frame.setContentPane(tabla);
        frame.add(panel);
        frame.pack();
        frame.setVisible(true);            
    }
    
   

}
